package cn.zsb.config;

import cn.zsb.servlet.TimeFilter;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Properties;

/**
 * @author oldliu
 * @since 1.0
 */
@Configuration
public class WebConfig {
    @Autowired
    private RedisTemplate redisTemplate;
    @Bean
    public FilterRegistrationBean<TimeFilter> addTimerFilter() {
        TimeFilter timer = new TimeFilter();
        timer.setRedisTemplate(redisTemplate);
        FilterRegistrationBean<TimeFilter> reg = new FilterRegistrationBean<TimeFilter>();
        reg.setFilter(timer);
        reg.addUrlPatterns("/*");
        reg.setOrder(1);
        return reg;
    }

    @Bean
    public DatabaseIdProvider databaseIdProvider() {
        DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
        Properties p = new Properties();
        p.setProperty("Oracle", "oracle");
        p.setProperty("MySQL", "mysql");
        p.setProperty("PostgreSQL", "postgresql");
        p.setProperty("DB2", "db2");
        p.setProperty("SQL Server", "sqlserver");
        databaseIdProvider.setProperties(p);
        return databaseIdProvider;
    }
}
